#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# First boot script
#if [ -x /root/firstboot/guest/yandi-first-boot.sh ]; then
#  (flock -x /tmp/.first-boot.lock -c "/root/firstboot/guest/yandi-first-boot.sh")&
#fi

rc_local_lock=/tmp/rc.local_lock

# Generate machine id
machine_id_file=/usr/sbin/kpc-machine-id.sh
if [ -x $machine_id_file ]; then
  (flock -x $rc_local_lock -c "$machine_id_file")&
fi

# Generate the SSL default snakeoil key/cert if non-existent
ssl_default_file=/usr/sbin/kpc-generate-default-snakeoil.sh
if [ -x $ssl_default_file ]; then
  (flock -x $rc_local_lock -c "$ssl_default_file")&
fi

# Generate the SSH keys if non-existent
dropbear_keygen_file=/usr/sbin/kpc-dropbear-keygen.sh
if [ -x $dropbear_keygen_file ]; then
  (flock -x $rc_local_lock -c "$dropbear_keygen_file")&
fi

exit 0
